package com.bluefoxyu.controller;


import com.bluefoxyu.domain.entity.Teacher;
import com.bluefoxyu.domain.result.Result;
import com.bluefoxyu.domain.vo.TeacherVO;
import com.bluefoxyu.service.ITeacherService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 教师信息表 前端控制器
 * </p>
 *
 * @author bluefoxyu
 * @since 2024-06-16
 */
@RestController
@RequestMapping("/teacher")
@RequiredArgsConstructor
@Tag(name ="管理页面老师接口")
public class TeacherController {

    private final ITeacherService teacherService;

    //维护（添加、删除和修改等基本任务）教师基本信息和教师所授课程等工作
    @Operation(summary = "添加教师基本信息")
    @PutMapping("/addTeacher")
    public Result<String> addTeacher(@RequestBody Teacher teacher) {
        teacherService.save(teacher);
        return Result.success("添加成功");
    }

    //删除教师基本信息
    @Operation(summary = "删除教师基本信息")
    @DeleteMapping("/deleteTeacher/{teacherId}")
    public Result<String> deleteTeacher(@PathVariable Long teacherId) {
        teacherService.deleteTeacher(teacherId);
        return Result.success("删除成功");
    }

    //修改教师基本信息
    @Operation(summary = "修改教师基本信息")
    @PostMapping("/updateTeacher")
    public Result<String> updateTeacher(@RequestBody Teacher teacher) {
        teacherService.updateById(teacher);
        return Result.success("修改成功");
    }


    // 统计不同职称的教师的数量、不同职称的教师的平均工资
    @Operation(summary = "统计不同职称的教师的数量、不同职称的教师的平均工资")
    @GetMapping("/statistics")
    public Result<TeacherVO> statistics() {
        return Result.success(teacherService.statistics());
    }

    @Operation(summary = "查询所有老师信息")
    @GetMapping("/getAllTeacher")
    public Result<List<Teacher>> getAllTeacher() {
        return Result.success(teacherService.list());
    }

}
